package cn.sciento.starter.social.wechat.enterprise.config;

import cn.sciento.starter.social.core.common.configurer.SocialConnectionFactoryBuilder;
import cn.sciento.starter.social.core.common.connect.SocialApiAdapter;
import cn.sciento.starter.social.core.common.connect.SocialConnectionFactory;
import cn.sciento.starter.social.core.common.connect.SocialServiceProvider;
import cn.sciento.starter.social.core.common.connect.SocialTemplate;
import cn.sciento.starter.social.core.common.constant.ProviderEnum;
import cn.sciento.starter.social.core.provider.Provider;
import cn.sciento.starter.social.wechat.enterprise.connection.WechatEnterpriseApiAdapter;
import cn.sciento.starter.social.wechat.enterprise.connection.WechatEnterpriseConnectionFactory;
import cn.sciento.starter.social.wechat.enterprise.connection.WechatEnterpriseServiceProvider;
import cn.sciento.starter.social.wechat.enterprise.connection.WechatEnterpriseTemplate;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WechatEnterpriseSocialBuilder implements SocialConnectionFactoryBuilder {
  public String getProviderId() {
    return ProviderEnum.wechat_enterprise.name();
  }
  
  public SocialConnectionFactory buildConnectionFactory(Provider provider) {
    String URL_AUTHORIZE = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect";
    String URL_GET_ACCESS_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
    String URL_GET_OPEN_ID = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
    String URL_GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/get";
    provider.setAuthorizeUrl("https://open.work.weixin.qq.com/wwopen/sso/qrConnect");
    provider.setAccessTokenUrl("https://qyapi.weixin.qq.com/cgi-bin/gettoken");
    provider.setOpenIdUrl("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo");
    provider.setUserInfoUrl("https://qyapi.weixin.qq.com/cgi-bin/user/get");
    WechatEnterpriseApiAdapter apiAdapter = new WechatEnterpriseApiAdapter();
    WechatEnterpriseTemplate template = new WechatEnterpriseTemplate(provider);
    WechatEnterpriseServiceProvider serviceProvider = new WechatEnterpriseServiceProvider(provider, (SocialTemplate)template);
    return (SocialConnectionFactory)new WechatEnterpriseConnectionFactory(provider, (SocialServiceProvider)serviceProvider, (SocialApiAdapter)apiAdapter);
  }
}
